/*
 * @Author: your name
 * @Date: 2024-04-30 00:16:24
 * @LastEditTime: 2024-04-30 00:20:09
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \.leetcode\530.二叉搜索树的最小绝对差.cpp
 */
/*
 * @lc app=leetcode.cn id=530 lang=cpp
 *
 * [530] 二叉搜索树的最小绝对差
 */

// @lc code=start
/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode() : val(0), left(nullptr), right(nullptr) {}
 *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
 *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
 * };
 */
class Solution {
public:
    vector<int> vec;
    void traversal(TreeNode* root){
        if(!root) return;
        traversal(root->left);
        vec.push_back(root->val);
        traversal(root->right);
    }
    int getMinimumDifference(TreeNode* root) {
        int min_val = INT_MAX;
        traversal(root);
        for(int i = 1; i < vec.size(); i++){
            int myabs = abs(vec[i]-vec[i-1]);
            min_val = (myabs < min_val?myabs:min_val); 
        }
        return min_val;
    }
};
// @lc code=end

